package com.example.testvolication.service.impl;

import com.example.testvolication.pojo.dto.GroupingDemo;
import com.example.testvolication.pojo.result.R;
import com.example.testvolication.pojo.valid.group.NameGroup;
import com.example.testvolication.service.TestGroupService;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

/**
 * @author zhangs
 * @date 2022/5/18 13:49
 */
@Service
public class TestGroupServiceImpl implements TestGroupService {
    private static R RESULT = R.ok("OK");

    private static R FAIL = R.fail(400 , "默认出错");

    @Override
    public R testGrouping(GroupingDemo groupingDemo) {
        R result = FAIL;
        Integer cased = groupingDemo.getIsCase();
        if (null == cased){
            return result;
        }
        switch (cased){
            case 1:
                result = testGrouping1( groupingDemo);
                break;
            case 2:
                result = testGrouping2(groupingDemo);
                break;
            case 3:
                result = testGrouping3(groupingDemo);
                break;
            default:
                break;
        }
        return result;
    }

    @Override
    public R testGrouping1(@Validated(NameGroup.class) GroupingDemo groupingDemo) {
        return RESULT;
    }

    @Override
    public R testGrouping2(GroupingDemo groupingDemo) {
        return RESULT;
    }

    @Override
    public R testGrouping3(GroupingDemo groupingDemo) {
        return RESULT;
    }
}
